package com.zhaoxi.project.md.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.project.md.domain.MdCategoryTree;
import com.zhaoxi.project.md.service.impl.MdCategoryTreeServiceImpl;
import com.zhaoxi.framework.web.controller.BaseController;
import com.zhaoxi.framework.web.domain.AjaxResult;
import com.zhaoxi.common.utils.poi.ExcelUtil;

/**
 * 物料产品分类Controller
 *
 * @author zhaoxi
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/md/tree")
public class MdCategoryTreeController extends BaseController {
    @Autowired
    private MdCategoryTreeServiceImpl mdCategoryTreeService;

    /**
     * 查询物料产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('md:tree:list')")
    @GetMapping("/list")
    public AjaxResult list(MdCategoryTree mdCategoryTree) {
        List<MdCategoryTree> list = mdCategoryTreeService.selectMdCategoryTreeList(mdCategoryTree);
        return success(list);
    }

    /**
     * 导出物料产品分类列表
     */
    @PreAuthorize("@ss.hasPermi('md:tree:export')")
    @Log(title = "物料产品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MdCategoryTree mdCategoryTree) {
        List<MdCategoryTree> list = mdCategoryTreeService.selectMdCategoryTreeList(mdCategoryTree);
        ExcelUtil<MdCategoryTree> util = new ExcelUtil<MdCategoryTree>(MdCategoryTree.class);
        util.exportExcel(response, list, "物料产品分类数据");
    }

    /**
     * 获取物料产品分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('md:tree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mdCategoryTreeService.selectMdCategoryTreeById(id));
    }

    /**
     * 新增物料产品分类
     */
    @PreAuthorize("@ss.hasPermi('md:tree:add')")
    @Log(title = "物料产品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MdCategoryTree mdCategoryTree) {
        return toAjax(mdCategoryTreeService.insertMdCategoryTree(mdCategoryTree));
    }

    /**
     * 修改物料产品分类
     */
    @PreAuthorize("@ss.hasPermi('md:tree:edit')")
    @Log(title = "物料产品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MdCategoryTree mdCategoryTree) {
        return toAjax(mdCategoryTreeService.updateMdCategoryTree(mdCategoryTree));
    }

    /**
     * 删除物料产品分类
     */
    @PreAuthorize("@ss.hasPermi('md:tree:remove')")
    @Log(title = "物料产品分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mdCategoryTreeService.deleteMdCategoryTreeByIds(ids));
    }
}